import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-05-02
 * Time:16:04
 */

/**
 * BM25二叉树的后序遍历
 */

public class postorderTraversal {
    public int[] postorderTraversal (TreeNode root) {
        // write code here
        List<Integer> list = new ArrayList<>();
        if (root != null) {
            postordrt(root, list);
        }
        int[] nums = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            nums[i] = list.get(i);
        }
        return nums;
    }

    private void postordrt(TreeNode root, List<Integer> list) {
        if (root == null){
            return;
        }
        postordrt(root.left,list);
        postordrt(root.right,list);
        list.add(root.val);
    }
}
